#ifndef NANE_LUASCRIPTMODULE_H
#   define NANE_LUASCRIPTMODULE_H

#   include "nane/ScriptSystem/IScriptSystem.h"

#   include <map>
#   include <string>
#   include <vector>

extern "C"
{
    #include "lua.h"
    #include "lauxlib.h"
}

namespace nane
{
    class LuaScriptModule
        : public IScriptModule
    {
    public:
        LuaScriptModule( const char* _moduleName );
        ~LuaScriptModule();

    public:
        bool Invoke( IInput* _args, IOutput* _results );
        const char* ToString();
        IScriptObject* ImportObject( const char* _objectName );
        IScriptObject* ExportFunction( const char* _className, const char* _functionName, IScriptFunction* _cfunction );
        void ReleaseObject( IScriptObject* _object );

    public:
        bool Initialize();
        bool Load( IInput* _input );
        int OnCFunction( lua_State* _state, const char* _functionName );
        bool Run();

    private:
        lua_State* m_state;
        typedef std::map<std::string, IScriptFunction*> TExportFunctionMap;
        TExportFunctionMap m_exportFunctionMap;
        typedef std::vector<byte> TByteVector;
        TByteVector m_returnBuffer;
        std::string m_name;
        int m_runRef;
    };
}   // namespace nane

#endif	// NANE_LUASCRIPTMODULE_H
